home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Common / CBaseCOM.cpp next >
Text File  |  1997-01-03  |  1KB  |  78 lines

  1. // =================================================================================
  2. //
  3. //    CBaseCOM.cpp                ©1996 Microsoft Corporation All rights reserved.
  4. //
  5. // =================================================================================
  6.  
  7. #include <compobj.h>
  8. #include <Platform.h>
  9. #include "CRefCount.h"
  10. #include "CBaseCOM.h"
  11.  
  12. #pragma mark === CBaseCOM::IUnknown ===
  13.  
  14. CBaseCOM::CBaseCOM(void)
  15. {
  16. }
  17.  
  18. CBaseCOM::~CBaseCOM(void)
  19. {
  20. }
  21.  
  22. //
  23. //  CBaseCOM::IUnknown::QueryInterface
  24. //
  25. //  Returns a pointer to the specified interface on a component to which a
  26. //  client currently holds an interface pointer.
  27. //
  28. STDMETHODIMP
  29. CBaseCOM::QueryInterface(REFIID inRefID, void** outObj)
  30. {
  31.     void* pv = nil;
  32.  
  33.     if ( inRefID == IID_IUnknown  )
  34.         pv = (void*)(IUnknown* ) this;
  35.  
  36.     *outObj = pv;
  37.     
  38.     // if we got an interface, ref it and return ok
  39.     if ( pv )
  40.     {
  41.             ((IUnknown*) pv)->AddRef();
  42.         return S_OK;
  43.     }
  44.     else
  45.         return E_NOINTERFACE;
  46. }
  47.  
  48.  
  49. //
  50. //  CBaseCOM::IUnknown::AddRef
  51. //
  52. //  Increments the reference count for the calling interface.
  53. //
  54. STDMETHODIMP_(Uint32)
  55. CBaseCOM::AddRef(void)
  56. {
  57.     return ++mRefCount;
  58. }
  59.  
  60.  
  61. //
  62. //  CBaseCOM::IUnknown::Release
  63. //
  64. //  Decrements the reference count for the calling interface on a object.  If
  65. //  the reference count on the object falls to zero, the object is freed.
  66. //
  67. STDMETHODIMP_(Uint32)
  68. CBaseCOM::Release(void)
  69. {
  70.     if (--mRefCount != 0)
  71.         return mRefCount;
  72.  
  73.     delete this;
  74.     return 0;
  75. }
  76.  
  77.  
  78.